﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace FB.Extensions
{
    public static class DateTimeExtensions
    {
        // convert to datetime to number of months 
        public static int MonthDifference(this DateTime lValue, DateTime rValue)
        {
            return (lValue.Month - rValue.Month) + 12 * (lValue.Year - rValue.Year);
        }


        public static DateTime ConvertFromUnixTimestamp(long seconds, DateTimeKind TimeZone = DateTimeKind.Utc)
        {
            var UnixEpoch = new DateTime(1970, 1, 1, 0, 0, 0, 0, TimeZone);
            return UnixEpoch.AddSeconds(seconds);
        }


        public static long ToUnixTimestamp(this DateTime lValue, DateTimeKind TimeZone = DateTimeKind.Utc)
        {
            DateTime origin = new DateTime(1970, 1, 1, 0, 0, 0, 0, TimeZone);
            return (long)(lValue - origin).TotalSeconds;
        }

    }
}
